home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
backgrnd.zip
/
BACKGRND.C
next >
Wrap
Text File
|
1989-09-18
|
3KB
|
137 lines
/*
* @(#) BACKGRND.C V1.0 Author: Shawn M. Regan
*
* Turbo C version 2.0
*
* This was an attempt at multitasking. The program first loads the
* address of it's controlling routine at interrupt vector x1C then
* terminates and stays resident via interrupt x27. Interrupt 1C is
* called at every clock tick which essentially equally divides it's
* time by two. Video display is done by writing to direct video ram
* as not to collide with dos or bios calls.
*
*/
#include <dos.h>
#include <stdlib.h>
void interrupt tsr_ap();
void tsr(),write_char(),set_vid_mem();
char far * vid_mem;
main()
{
struct address {
char far *p;
};
/* Compute interrupt's address, store in addr */
struct address far *addr = ( struct address far *) 112;
clrscr();
printf("Installed...BACKGNRD by Shawn Regan, Atlanta, GA.\n\n");
printf("This program is not copyrighted and hereby declared as public domain.\n");
printf("It provides a good example of using interrupt calls 27 & 1C. If you\n");
printf("are interested in this you should pick up these two books which were\n");
printf("instrumental in writing this program:\n\n");
printf("The C Power User's Guide - By Herbert Schildt\n");
printf("The Peter Norton Programmer's guide to the IBM PC\n\n");
printf("By the way if you use and enjoy this program please take $10 and stick\n");
printf("it in your pocket. I have a real job and don't need your money. Better\n");
printf("yet go and buy Herb Schildt's book which contains a wealth of advanced\n");
printf("programming information and techniques.\n");
sleep(5);
addr->p = (char far *) tsr_ap;
set_vid_mem();
tsr(1200);
}
void interrupt tsr_ap()
{
static char alpha[] = { "ShawnRegan" };
static int j=0,i=0;
i=j/10;
write_char(alpha[i]);
if (++j > 99 ) j=0; /* Each character get's 10 turns in a row */
}
/* Set video mode - directly from the C power user's guide */
void set_vid_mem()
{
int vmode;
vmode=video_mode();
if ((vmode != 2 ) && (vmode != 3 ) && (vmode != 7 )) {
printf("video must be in 80 column text mode");
exit(1);
}
if ( vmode == 7 ) vid_mem = (char far *) 0xB0000000;
else vid_mem = ( char far *) 0xB8000000;
}
/* Load program and leave in memory - from C power user's guide also */
void tsr(size)
unsigned size;
{
union REGS r;
r.h.ah = 49; /* Terminate but stay resident */
r.h.al = 0; /* Return code */
r.x.dx = size;
int86(0x21,&r,&r);
}
/* Compute new character's position then send the character directly to
* video ram.
*/
void write_char(ch)
char ch;
{
register int a,b;
static int x=0,dx=1,y=24,dy=1;
char far *v;
v=vid_mem+(x*160)+y*2; /* Clear previous character */
*v=' ';
a=x+dx;
b=y+dy;
v=vid_mem+(a*160)+b*2; /* If occupied compute random new direction */
if ( *v != ' ' || a > 24 || a < 0 || b > 79 || b < 0 ) {
do {
dx=rnd();
dy=rnd();
} while(dx==0 && dy==0); /* Both axis cannot move zero units */
}
else { /* not occupied continue on current course */
x=a;
y=b;
}
v=vid_mem+(x*160)+y*2; /* Write new character */
*v=ch;
}
/* Get current video mode, C power user's guide */
int video_mode()
{
union REGS r;
r.h.ah = 15;
return int86(0x10, &r, &r) & 255;
}
/* Return random, -1, 0 or 1 */
int rnd()
{
int i;
i=rand();
if ( i < 10000) return -1;
if ( i < 20000) return 0;
return 1;
}